package com.stydy.javadynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 代理处理器类
 * Created by hhy on 2016/4/28.
 */
public class ProxyHandler implements InvocationHandler {

   private  Object proxied;

    public ProxyHandler(Object proxied) {
        this.proxied = proxied;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("proxy:"+proxy.getClass().getName());
        System.out.println("method:"+method.getName());
        System.out.println("args:"+args);
        System.out.println("invoke proxied method 之前...");
        //在转调具体目标对象之前，可以执行一些功能处理

        //普通的java反射代码，通过反射执行委托类的某方法
        Object object = method.invoke(proxied,args);
        System.out.println("执行委托类方法返回的object:"+object);
        System.out.println("invoke proxied method 之后...");
        //在转调具体目标对象之后，可以执行一些功能处理
        return null;
    }
}
